package cn.glc.daily.life.web.support;

import org.springframework.transaction.support.TransactionSynchronizationAdapter;
import org.springframework.transaction.support.TransactionSynchronizationManager;

/**
 * 事务 aop 后置处理
 *
 * @author simon
 * @date 2021/6/1 16:22
 * @copyright:
 * @modifier
 * @motto a no talent, people who have to study hard
 */
public class TransactionalSupport {

    public static void afterCompletion(Runnable runnable) {
        if (TransactionSynchronizationManager.isActualTransactionActive()) {
            TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
                @Override
                public void afterCompletion(int status) {
                    runnable.run();
                }
            });
        }
    }
}
